using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency;
using Konst3d.Efficiency.Suite;
using Konst3d.Efficiency.Suite.SparsedBinary;
using System.Windows;

// http://msdn.microsoft.com/en-us/library/ff798384.aspx

namespace PEM
{
    public enum SortingDirection
    {
        Ascending,
        Descending
    }

    internal partial class MainWindowViewModel: ViewModelBase // MainViewModel
    {
        internal delegate void SuiteActionHandler(MainWindowViewModel sender);

        #region Events

        public event SuiteActionHandler SuiteOpened;
        public event SuiteActionHandler SuiteClosed;
        public event SuiteActionHandler SuiteCreated;
        public event SuiteActionHandler SuiteDeleted;

        #endregion // Events

        #region Properties

        public CommandsCollection Commands
        {
            get;
            private set;
        }

        public IEfficiencySuite Suite
        {
            get;
            private set;
        }

        public NotesViewModel NotesModel
        {
            get;
            private set;
        }

        public BuysViewModel BuysModel
        {
            get;
            private set;
        }

        public CountDownTimersViewModel CountDownTimersModel
        {
            get;
            private set;
        }

		public MilestonesViewModel MilestonesModel
		{
			get;
			private set;
		}

		public TasksViewModel TasksModel
		{
			get;
			private set;
		}

		public MonitorsViewModel MonitorsModel
		{
			get;
			private set;
		}

		public CountersViewModel CountersModel
		{
			get;
			private set;
		}

        #endregion // Properties

		#region Constructor

		public MainWindowViewModel(Window window)
        {
            Contract.Requires(window != null);

            _window = window;
            _createSuiteDialog = new CreateSuiteDialog(_cryptographicEngines);
            _openSuiteDialog = new OpenFileDialog();
            _suiteLoginDialog = new SuiteLoginDialog();

            Commands = new CommandsCollection(this);
            AppCommands = new AppCommandsCollection(this);

            NotesModel = new NotesViewModel(_window, this);
            BuysModel = new BuysViewModel(_window, this);
            CountDownTimersModel = new CountDownTimersViewModel(_window, this);
			MilestonesModel = new MilestonesViewModel(_window, this);
			TasksModel = new TasksViewModel(_window, this);
			MonitorsModel = new MonitorsViewModel(_window, this);
			CountersModel = new CountersViewModel(_window, this);
        }

		#endregion // Constructor

		#region Overriden Methods

		protected override void DisposeManaged()
        {
            base.DisposeManaged();

            NotesModel.Dispose();
            NotesModel = null;

            BuysModel.Dispose();
            BuysModel = null;

            CountDownTimersModel.Dispose();
            CountDownTimersModel = null;

			MilestonesModel.Dispose();
			MilestonesModel = null;

			TasksModel.Dispose();
			TasksModel = null;

			MonitorsModel.Dispose();
			MonitorsModel = null;

			CountersModel.Dispose();
			CountersModel = null;

            _createSuiteDialog.Close();
            _createSuiteDialog = null;

            _suiteLoginDialog.Close();
            _suiteLoginDialog = null;

            _cryptographicEngines = null;
        }

		#endregion // Overriden Methods

		#region Fields

		private Window _window;
        private CreateSuiteDialog _createSuiteDialog;
        private OpenFileDialog _openSuiteDialog;
        private SuiteLoginDialog _suiteLoginDialog;
        private ICryptographicEngine[] _cryptographicEngines = new ICryptographicEngine[] { new NullBinaryEncoder(Encoding.UTF8), new SimpleBinaryEncoder(Encoding.UTF8) };

        #endregion // Fields
    }
}
